package com.ynny.service;

import com.ynny.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
public class AccountServiceImpl implements AccountService {

    //转账方法

    @Autowired
    AccountDao accountDao;

    public void transfer(){
        //A 给 B转账
        // A 扣钱 (给A账户里面的余额 数据库修改)

        accountDao.subAccountBalance("A1001",new BigDecimal(100));
        // B 加钱 (给B账户里面的余额 数据库修改)
        accountDao.addAccountBalance("B1002",new BigDecimal(100));


    }


    @Transactional
    @Override
    public void transfer(String outAccount,
                         String inAccount,
                         BigDecimal amount) {
        // A 扣钱 (给A账户里面的余额 数据库修改)
        int i = accountDao.subAccountBalance(outAccount, amount);

        System.out.println(1/0);
        // B 加钱 (给B账户里面的余额 数据库修改)
        int j = accountDao.addAccountBalance(inAccount, amount);


    }
}
